package com.oa.admin.controller;

import com.joneying.common.annotation.CommonController;
import com.joneying.common.web.response.Resp;
import com.oa.admin.dto.CollarUseApplyAddDTO;
import com.oa.admin.dto.CollarUseApplyListDTO;
import com.oa.admin.service.ICollarUseApplyService;
import com.oa.admin.vo.CollarUseApplyDetailsVO;
import com.oa.admin.vo.InventoryUserListVO;
import com.oa.core.BaseController;
import com.oa.core.PageResult;
import com.oa.core.exception.BusinessException;
import com.oa.core.exception.DataIsEmptyException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Description;
import org.springframework.web.bind.annotation.*;

@Api(description = "领用")
@RequestMapping("/collarUseApply")
@RestController
public class CollarUseApplyController extends BaseController {

    @Autowired
    private ICollarUseApplyService inventoryUserService;

    @GetMapping("/list")
    @CommonController
    @Description("列表")
    @ApiOperation(value = "列表")
    public Resp<PageResult<InventoryUserListVO>> list(CollarUseApplyListDTO collarUseApplyListDTO){
        collarUseApplyListDTO.setUserId(getLoginUserId());
        return new Resp<PageResult<InventoryUserListVO>>().success(inventoryUserService.findInventoryUserList(collarUseApplyListDTO));
    }

    @GetMapping("/record/list")
    @CommonController
    @Description("列表")
    @ApiOperation(value = "列表")
    public Resp<PageResult<InventoryUserListVO>> listRecord(CollarUseApplyListDTO collarUseApplyListDTO){
        collarUseApplyListDTO.setUserId(getLoginUserId());
        return new Resp<PageResult<InventoryUserListVO>>().success(inventoryUserService.findInventoryUserListApply(collarUseApplyListDTO));
    }

    @GetMapping("/{id}")
    @CommonController
    @Description("列表")
    @ApiOperation(value = "列表")
    public Resp<CollarUseApplyDetailsVO> findById(@PathVariable String id){
        return new Resp().success(inventoryUserService.findCollarUseApplyDetails(id));
    }

    @PostMapping("")
    @CommonController
    @Description("新增申请")
    @ApiOperation(value = "新增申请")
    public Resp add(@RequestBody CollarUseApplyAddDTO collarUseApplyAddDTO) throws DataIsEmptyException, BusinessException {
        return inventoryUserService.add(getLoginUserId(), collarUseApplyAddDTO);
    }
}
